home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / dos / biostest.c next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  3.6 KB  |  119 lines

  1. /*
  2.  * BIOSTEST.C
  3.  *
  4.  * Test for _bios_xxxxx function group.
  5.  * Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
  6.  *
  7.  * Tested with the following DOS C compilers:
  8.  *   DJGPP v2.0
  9.  *   Borland C\C++ 3.1
  10.  *   Borland C\C++ 4.02
  11.  *   Borland C\C++ 4.5
  12.  *   Microsoft C 6.00A
  13.  *   Microsoft C\C++ 7.00
  14.  *   Microsoft Visual C\C++ 1.5
  15.  *   Symantec C\C++ 6.11
  16.  *   Watcom C\C++ 9.5
  17.  *   Watcom C\C++ 10.0A
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <bios.h>
  22.  
  23. static unsigned char diskbuf[2048];
  24.  
  25. void main(void)
  26. {
  27.   struct diskinfo_t di;
  28.   unsigned i, j, status, port;
  29.   unsigned char *p, linebuf[17];
  30.   union
  31.   {                               /* Access equiment either as:    */
  32.     unsigned u;                   /*   unsigned or                 */
  33.     struct                        /*   bit fields                  */
  34.     {
  35.       unsigned diskflag : 1;      /* Diskette drive installed?     */
  36.       unsigned coprocessor : 1;   /* Coprocessor? (except on PC)   */
  37.       unsigned sysram : 2;        /* RAM on system board           */
  38.       unsigned video : 2;         /* Startup video mode            */
  39.       unsigned disks : 2;         /* Drives 00=1, 01=2, 10=3, 11=4 */
  40.       unsigned dma : 1;           /* 0=Yes, 1=No (1 for PC Jr.)    */
  41.       unsigned comports : 3;      /* Serial ports                  */
  42.       unsigned game : 1;          /* Game adapter installed?       */
  43.       unsigned modem : 1;         /* Internal modem?               */
  44.       unsigned printers : 2;      /* Number of printers            */
  45.     } bits;
  46.   } equip;
  47.  
  48.  
  49.   /* _bios_equiplist() test */
  50.   equip.u = _bios_equiplist();
  51.   printf( "Disk drive:          %s\n", equip.bits.diskflag ? "Yes" : "No" );
  52.   printf( "Coprocessor:         %s\n", equip.bits.coprocessor ? "Yes" : "No" );
  53.   printf( "Game adapter:        %s\n", equip.bits.game ? "Yes" : "No" );
  54.   printf( "Serial ports:        %d\n", equip.bits.comports);
  55.   printf( "Number of printers:  %d\n\n", equip.bits.printers);
  56.  
  57.  
  58.   /* _bios_memsize() test */
  59.   printf( "Size of memory:      %i K\n\n", _bios_memsize());
  60.  
  61.  
  62.   /* _bios_printer() test */
  63.   puts("Test of paralel ports:");
  64.   for(port=0; port < equip.bits.printers; port++)
  65.   {
  66.     status = _bios_printer(_PRINTER_STATUS, port, 0);
  67.     printf("  LPT%c status: PRINTER IS %s\n", '1' + port, ( status == 0x90 ) ? "READY" : "NOT READY");
  68.   }
  69.  
  70.  
  71.   /* _bios_serialcom() test */
  72.   puts("\nTest of serial ports:");
  73.   for(port=0; port < equip.bits.comports; port++)
  74.   {
  75.     status = _bios_serialcom(_COM_STATUS, port, 0);
  76.  
  77.     /* Report status of each serial port and test whether there is a
  78.      * responding device (such as a modem) for each. If data-set-ready
  79.      * and clear-to-send bits are set, a device is responding.
  80.      */
  81.     printf("  COM%c status: DEVICE IS %s\n", '1' + port, (status & 0x0030) ? "ACTIVE" : "NOT ACTIVE" );
  82.   }
  83.  
  84.  
  85.   /* _bios_disk() test, read the partition table from C: drive. */
  86.   puts("\nContents of master boot sector:");
  87.   di.drive    = 0x80;
  88.   di.head     = 0;
  89.   di.track    = 0;
  90.   di.sector   = 1;
  91.   di.nsectors = 1;
  92.   di.buffer   = diskbuf;
  93.  
  94.   /* Try reading disk three times before giving up. */
  95.   for(i=0; i<3; i++)
  96.   {
  97.     status = _bios_disk(_DISK_READ, &di) >> 8;
  98.     if ( !status )
  99.       break;
  100.   }
  101.   if ( status )
  102.     printf("Disk error: 0x%.2x\n", status);
  103.   else
  104.   {
  105.     for(p=diskbuf, i=j=0; i<512; i++, p++)
  106.     {
  107.       linebuf[j++] = (*p > 32) ? *p : '.';
  108.       printf("%.2x ", *p);
  109.       if (j == 16)
  110.       {
  111.         linebuf[j] = '\0';
  112.         printf(" %16s\n", linebuf);
  113.         j = 0;
  114.       }
  115.     }
  116.   }
  117.  
  118. }
  119.